module ApplicationHelper
  
  #被访问: :browser_version
  def accessed_by?(args = {})
    request.env['HTTP_USER_AGENT'].downcase.index(args[:browser_version])
  end
  
  # qtip args :content :tip :target :tooltip
  def qtip(jquery_selector,args = {})
    raw "$('#{jquery_selector}').qtip({
     content: '#{args[:content]}',
     style: {
       name : 'cream',
       tip: '#{args[:tip]}',
       border: {
         radius: 5
       }
     },           
     position: {
       corner: {
         target: '#{args[:target]}',
         tooltip: '#{args[:tooltip]}'
       }
     },
     show: {
       ready : true
     }
  })"
  end

  def loading_image_tag( size = :normal, options = {})
    options[:title] ||= '读取中...'
    options[:alt] ||= options[:title]
    case size
    when :large
      options[:class] ||= 'loading large'
      image_tag 'loading/54x18.gif', options
    when :normal
      options[:class] ||= 'loading normal'
      image_tag 'loading/36x12.gif', options
    when :small
      options[:class] ||= 'loading small'
      image_tag 'loading/24x8.gif', options
    else
      raise "未知尺码：#{size}"
    end
  end

end
